import React from 'react';
import { Modal, Button, Form, Input } from 'antd';

const Item = Form.Item;
const TextArea = Input.TextArea;

@Form.create()
class Components extends React.Component {
  /**
   * 提交表单到父组件
   */
  onOk = () => {
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        this.props.editor(values);
      }
    });
  };
  clear = () => {
    this.props.form.resetFields();
  };

  render() {
    const {
      visible,
      formatData,
      toggleVisible,
      form: { getFieldDecorator },
    } = this.props;
      

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
    };
    return (
      <Modal
        title="编辑角色"
        afterClose={this.clear}
        visible={visible}
        onCancel={toggleVisible}
        onOk={this.onOk}
      >
        <Form>
          <Item {...formItemLayout} label="角色名称">
            {getFieldDecorator('name', {
              rules: [{ required: true, message: '不能为空' }],
              initialValue: formatData.name,
            })(<Input />)}
          </Item>
          <Item {...formItemLayout} label="角色描述">
              {getFieldDecorator('remark', {
                rules: [{ required: true, message: '不能为空' }],
                initialValue: formatData.remark,
              })(<TextArea rows={4} />)}
            </Item>
        </Form>
      </Modal>
    );
  }
}

export default Components;
